/*
 *  PMVect.h
 *  PezMonkey
 *
 *  Created by Spence DiNicolantonio on 10/28/09.
 *  Copyright 2009 Necrosoft. All rights reserved.
 *
 */


/**
 * A 2-dimensional vector. This structure is interchangeable with Chipmunk's 
 * cpVect structure.
 */

#import <Foundation/Foundation.h>
#import "chipmunk.h"


#pragma mark Type Definition
typedef cpVect PMVect;
static const PMVect PMVectZero = {0.0, 0.0};


#pragma mark -
#pragma mark Static Inline Functions

static inline PMVect PMVectMake(const PMFloat x, const PMFloat y) {
	return (PMVect) cpv(x, y);
}

static inline PMVect PMVectAdd(const PMVect v1, const PMVect v2) {
	return (PMVect) cpvadd(v1, v2);
}
							   
static inline PMVect PMVectNeg(const PMVect v) {
	return (PMVect) cpvneg(v);
}
							   
static inline PMVect PMVectSub(const PMVect v1, const PMVect v2) {
	return (PMVect) cpvsub(v1, v2);
}
							   
static inline PMVect PMVectMult(const PMVect v, const PMFloat s) {
	return (PMVect) cpvmult(v, s);
}
							   
static inline PMFloat PMVectDot(const PMVect v1, const PMVect v2) {
	return cpvdot(v1, v2);
}
							   
static inline PMFloat PMVectCross(const PMVect v1, const PMVect v2) {
	return cpvcross(v1, v2);
}
							   
static inline PMVect PMVectPerp(const PMVect v) {
	return (PMVect) cpvperp(v);
}
							   
static inline PMVect PMVectRPerp(const PMVect v) {
	return (PMVect) cpvrperp(v);
}
							   
static inline PMVect PMVectProject(const PMVect v1, const PMVect v2) {
	return (PMVect) cpvproject(v1, v2);
}
							   
static inline PMVect PMVectRotate(const PMVect v1, const PMVect v2) {
	return (PMVect) cpvrotate(v1, v2);
}
							   
static inline PMVect PMVectUnrotate(const PMVect v1, const PMVect v2) {
	return (PMVect) cpvunrotate(v1, v2);
}

static inline NSUInteger PMVectCount(PMVect vectorArray[]) {
	return sizeof(vectorArray) / 2;
}
	

#pragma mark -
#pragma mark Other Functions

static PMFloat PMVectLength(const PMVect v) {
	return cpvlength(v);
}

static PMFloat PMVectLengthSQ(const PMVect v) {
	return cpvlengthsq(v);
}

static PMVect PMVectNormalize(const PMVect v) {
	return (PMVect) cpvnormalize(v);
}

static PMVect PMVectForAngle(const PMFloat a) {
	return (PMVect) cpvforangle(a);
}

static PMFloat PMVectToAngle(const PMVect v) {
	return cpvtoangle(v);
}

static NSString* PMVectToString(const PMVect v) {
	return [NSString stringWithFormat:@"(%0.3f, %0.3f)", v.x, v.y];
}
